package t327.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import t327.mapper.StyleNumberMapper;
import t327.pojo.Client;

import t327.pojo.OrderForm;
import t327.pojo.QuotationList;
import t327.pojo.StyleNumber;
import t327.pojo.font.LuiTableEntity;
import t327.pojo.views.OrderColorSizeClientView;
import t327.pojo.views.OrderListView;
import t327.service.iter.IOrderFromService;

import java.util.HashMap;
import java.util.List;
@RestController
@RequestMapping("orderFrom")

public class OrderFromController {
    @Autowired
    private IOrderFromService orderFromService;
    @Autowired
    private StyleNumberMapper styleNumberMapper;
    //订单录入
    @RequestMapping("add")
    @ResponseBody
    public HashMap<Object,Object> addOrder(@RequestBody OrderForm orderForm) {
        List<Long> listId = orderForm.getListId();//把orderForm实体类里面的List拿出来
        HashMap<Object, Object> map = orderFromService.addOrder(orderForm,listId);
        return map;
    }
    @RequestMapping("updateStyleNumber")
    @ResponseBody
    public  String UpdateMember(@RequestBody Long id){
        // 调用Service层方法并传递ID参数
        //  styleNumberMapper.UpdateStyleNumber(id);
        int i = styleNumberMapper.UpdateStyleNumber(id);
        if (i > 0) {
            return "success";
        }
        return "false";
    }
    //查询订单列表
    @RequestMapping("getOrderColorSizeClient")
    public LuiTableEntity getOrderColorSizeClient(@RequestParam(value = "page") Integer pageNum, @RequestParam(value = "limit")Integer pageSize){
/*
*     "code": res.status, //解析接口状态
      "msg": res.message, //解析提示文本
      "count": res.total, //解析数据长度
      "data": res.data.item //解析数据列表
* */
        PageHelper.startPage(pageNum,pageSize);
        LuiTableEntity luiTableEntity = new LuiTableEntity<OrderListView>();
        PageInfo<OrderListView> orderListView = new PageInfo<>(orderFromService.orderList());
        List<OrderListView> products = orderListView.getList();
        long total = orderListView.getTotal();
        if(products!=null&&products.size()>0){
            luiTableEntity.setCode("0");
            luiTableEntity.setMsg("查询成功");
            luiTableEntity.setCount(total);
            luiTableEntity.setData(products);
        }else{
            luiTableEntity.setCode("203");
            luiTableEntity.setMsg("查询失败");

        }
        System.out.println("1");
        System.out.println(products);


        return   luiTableEntity;

    }
    //订单客户名称查询
    @RequestMapping("getClientClientId")
    @ResponseBody
    public List<Client> getClientClientId(){
        return orderFromService.getClientId();
    }

//    @RequestMapping("getClientName")
//    @ResponseBody
//    public List<Client> getClientName(String clientName){
//        return orderFromService.getClientName(clientName);
//    }

    @RequestMapping("getClientIdList")
    @ResponseBody
    public List<Client> getClientIdList(Long clientId){
        return orderFromService.getClientIdList(clientId);
    }
    @RequestMapping("getStyleNumber")
    @ResponseBody
    public List<StyleNumber> getStyleNumber(){
        return styleNumberMapper.getStyleNumber();
    }
    @RequestMapping("getOrderFromCount")
    @ResponseBody
    public int getOrderFromCount(){
        return styleNumberMapper.orderFromCount();
    }
    @RequestMapping("getStyleNumberList")
    public LuiTableEntity getStyleNumberList(@RequestParam(value = "page") Integer pageNum, @RequestParam(value = "limit")Integer pageSize){
/*
*     "code": res.status, //解析接口状态
      "msg": res.message, //解析提示文本
      "count": res.total, //解析数据长度
      "data": res.data.item //解析数据列表
* */
        PageHelper.startPage(pageNum,pageSize);
        LuiTableEntity luiTableEntity = new LuiTableEntity<StyleNumber>();
        PageInfo<StyleNumber> orderColorSizeClientview = new PageInfo<>(styleNumberMapper.getStyleNumberList());
        List<StyleNumber> products = orderColorSizeClientview.getList();
        long total = orderColorSizeClientview.getTotal();
        if(products!=null&&products.size()>0){
            luiTableEntity.setCode("0");
            luiTableEntity.setMsg("查询成功");
            luiTableEntity.setCount(total);
            luiTableEntity.setData(products);
        }else{
            luiTableEntity.setCode("203");
            luiTableEntity.setMsg("查询失败");

        }
        System.out.println("1");
        System.out.println(products);


        return   luiTableEntity;


    }

    //渲染订单列表下拉框
    @RequestMapping("getOrderFrom")
    @ResponseBody
    public List<OrderForm> getOrderFrom(){return styleNumberMapper.getOrderFromBayId();}
    //更改审核已审核
    @RequestMapping("getModifyOrder")
    @ResponseBody
    public int updateStudent(Long orderId) {
        int map = orderFromService.UodateOrder(orderId);
        return map;

    }
    //关键词查询
    @RequestMapping("getProductNameList")
    @ResponseBody
    public List<OrderListView> getProductNameList(String productName,String quotationNumber,Long orderStatus){return orderFromService.orderList();}
    //渲染主页订单
    @RequestMapping("renderHomeOrder")
    @ResponseBody
    public List<OrderColorSizeClientView> renderHomeOrder() {
        return orderFromService.renderHomeOrder();
    }
    //渲染主页订单号查询
    @RequestMapping("renderHomeOrderNumberQuery")
    @ResponseBody
    public List<OrderColorSizeClientView> renderHomeOrderNumberQuery(String quotation) {
        return orderFromService.renderHomeOrderNumberQuery(quotation);
    }
    //订单列表多个查询
    @RequestMapping("getOrderListView")
    @ResponseBody
    public List<OrderListView> orderListView(OrderListView orderListView) {
        return orderFromService.ConditionQuery(orderListView);
    }
    //订单列表多个查询
    @RequestMapping("getOrderButton")
    @ResponseBody
    public List<OrderForm> getOrderButton(Long orderId) {
        return orderFromService.ListButton(orderId);
    }
    //点击款号显示金额
    @RequestMapping("getQuotationList")
    @ResponseBody
    public List<QuotationList> getQuotationList(@RequestBody List<String> styleNumberIds){
        return orderFromService.getQuotationList(styleNumberIds);
    }
}

